package com.ff.miaosha.result;

import lombok.ToString;

@ToString
public class CodeMsg {

    private int code;

    private String msg;

    //通用异常
    public static CodeMsg SUCCESS=new CodeMsg(0,"success");
    public static CodeMsg SERVER_ERROR=new CodeMsg(500100,"服务端异常");
    public static CodeMsg BIND_ERROR=new CodeMsg(500101,"参数校验异常：%s");

    //登录模块 5002XX
    public static CodeMsg MOBILE_NOT_EXIST=new CodeMsg(500201,"手机号不存在");
    public static CodeMsg PASSWORD_ERROR=new CodeMsg(500201,"密码错误");
    public static CodeMsg SESSION_ERROR=new CodeMsg(500202,"session异常");
    public static CodeMsg ACCESS_LIMIT_REACHED =new CodeMsg(500203,"访问太频繁，请稍后再试");

    //商品模块5003XX

    //订单模块5004XX
    public static CodeMsg ORDER_NOT_EXIST =new CodeMsg(500400,"订单不存在");

    //秒杀模块5005XX
    public static CodeMsg MIAO_SHA_OVER=new CodeMsg(500500,"秒杀已结束");
    public static CodeMsg REPETE_MIAOSHA=new CodeMsg(500501,"重复秒杀");
    public static CodeMsg REQUEST_ILLEGAL=new CodeMsg(500502,"请求地址无效");
    public static CodeMsg MIAO_SHA_FAIL=new CodeMsg(500503,"秒杀失败");


    private CodeMsg(int code,String msg){
        this.code=code;
        this.msg=msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public CodeMsg fillArgs(Object... args){
        int code=this.code;
        String message=String.format(this.msg,args);
        return new CodeMsg(code,message);
    }

}
